home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / exef.c < prev    next >
C/C++ Source or Header  |  1993-06-19  |  11KB  |  452 lines

  1. /*****************************************************************************
  2.  
  3.     ExeF()
  4.  
  5.     This function executes a F command.
  6.     nF_    Destructive search and replace
  7.     F'    Flow to end of conditional
  8.     F<    Flow to start of iteration
  9.     F>    Flow to end of iteration
  10.     F|    Flow to ELSE part of conditional
  11.     m,nFB    Search between locations m and n
  12.     nFB    Search, bounded by n lines
  13.     m,nFC    Search and replace between locations m and n
  14.     nFC    Search and replace over n lines
  15.     nFD    Search and delete string
  16.     nFK    Search and delete intervening text
  17.     nFN    Global string replace
  18.     FR    Replace last string
  19.     nFS    Local string replace
  20.  
  21. *****************************************************************************/
  22.  
  23. #include "zport.h"        /* define portability identifiers */
  24. #include "tecoc.h"        /* define general identifiers */
  25. #include "defext.h"        /* define external global variables */
  26. #include "chmacs.h"        /* define character processing macros */
  27. #include "deferr.h"        /* define identifiers for error messages */
  28.  
  29. #if USE_PROTOTYPES
  30. static DEFAULT ExeFBr(void);
  31. static DEFAULT ExeFC(void);
  32. static DEFAULT ExeFD(void);
  33. static DEFAULT ExeFGt(void);
  34. static DEFAULT ExeFK(void);
  35. static DEFAULT ExeFLs(void);
  36. static DEFAULT ExeFN(void);
  37. static DEFAULT ExeFR(void);
  38. static DEFAULT ExeFS(void);
  39. static DEFAULT ExeFSQ(void);
  40. static DEFAULT ExeFUn(void);
  41. #endif
  42.  
  43. /*****************************************************************************
  44.  
  45.     ExeFBr()
  46.  
  47.     This function executes a F| (F-bar) command.
  48.  
  49. *****************************************************************************/
  50.  
  51. static DEFAULT ExeFBr()            /* execute an F| command */
  52. {
  53.     DBGFEN(1,"ExeFBr",NULL);
  54.  
  55.     CmdMod = '\0';                /* clear modifiers flags */
  56.     EStTop = EStBot;            /* clear expression stack */
  57.  
  58.     DBGFEX(1,DbgFNm,"FlowEE()");
  59.     return FlowEE();
  60. }
  61.  
  62. /*****************************************************************************
  63.  
  64.     ExeFC()
  65.  
  66.     This function executes a FC command.
  67.  
  68. *****************************************************************************/
  69.  
  70. static DEFAULT ExeFC()            /* execute an FC command */
  71. {
  72.     DBGFEN(1,"ExeFC",NULL);
  73.  
  74.     if (CmdMod & DCOLON) {            /* if it's ::FC */
  75.         ErrStr(ERR_ILL, "::FC");    /* illegal command "::FC" */
  76.         DBGFEX(1,DbgFNm,"FAILURE");
  77.         return FAILURE;
  78.     }
  79.  
  80.     SrcTyp = FB_SEARCH;
  81.     if (Replac() == FAILURE) {
  82.         DBGFEX(1,DbgFNm,"FAILURE");
  83.         return FAILURE;
  84.     }
  85.  
  86.     CmdMod = '\0';                /* clear modifiers flags */
  87.  
  88.     DBGFEX(1,DbgFNm,"SUCCESS");
  89.     return SUCCESS;
  90. }
  91.  
  92. /*****************************************************************************
  93.  
  94.     ExeFD()
  95.  
  96.     This function executes a FD command.
  97.  
  98. *****************************************************************************/
  99.  
  100. static DEFAULT ExeFD()            /* execute an FD command */
  101. {
  102.     DBGFEN(1,"ExeFD",NULL);
  103.  
  104. /*
  105.  * The command m,nFD is illegal: the user should use m,nFB
  106.  */
  107.  
  108.     if (CmdMod & MARGIS) {            /* if it's m,nFD */
  109.         ErrStr(ERR_ILL, "m,nFD");    /* illegal command "m,nFD" */
  110.         DBGFEX(1,DbgFNm,"FAILURE");
  111.         return FAILURE;
  112.     }
  113.  
  114.     if (CmdMod & DCOLON) {            /* if it's ::FD */
  115.         ErrStr(ERR_ILL, "::FD");    /* illegal command "::FD" */
  116.         DBGFEX(1,DbgFNm,"FAILURE");
  117.         return FAILURE;
  118.     }
  119.  
  120.     SrcTyp = S_SEARCH;
  121.     if (Search(FALSE) == FAILURE) {
  122.         DBGFEX(1,DbgFNm,"FAILURE");
  123.         return FAILURE;
  124.     }
  125.  
  126.     if (Matchd) {                /* if successful search */
  127.         GapBeg += RefLen;        /* delete found string */
  128.     }
  129.  
  130.     CmdMod = '\0';                /* clear modifiers flags */
  131.  
  132.     DBGFEX(1,DbgFNm,"SUCCESS");
  133.     return SUCCESS;
  134. }
  135.  
  136. /*****************************************************************************
  137.  
  138.     ExeFGt()
  139.  
  140.     This function executes a F> command.
  141.  
  142. *****************************************************************************/
  143.  
  144. static DEFAULT ExeFGt()            /* execute an F> command */
  145. {
  146.     DBGFEN(1,"ExeFGt",NULL);
  147.  
  148.     if (LStTop == LStBot) {            /* if not in a loop */
  149.         DBGFEX(1,DbgFNm,"FAILURE");
  150.         return FAILURE;
  151.     }
  152.  
  153.     if (FlowEL() == FAILURE) {        /* flow to end-of-loop */
  154.         DBGFEX(1,DbgFNm,"FAILURE");
  155.         return FAILURE;
  156.     }
  157.     CBfPtr--;                /* backup before the ">" */
  158.     LStTop++;                /* cancel what FlowEL did */
  159.     CmdMod = '\0';                /* clear modifiers flags */
  160.     EStTop = EStBot;            /* clear expression stack */
  161.  
  162.     DBGFEX(1,DbgFNm,"SUCCESS");
  163.     return SUCCESS;
  164. }
  165.  
  166. /*****************************************************************************
  167.  
  168.     ExeFK()
  169.  
  170.     This function executes a FK command.
  171.  
  172. *****************************************************************************/
  173.  
  174. static DEFAULT ExeFK()            /* execute an FK command */
  175. {
  176.     DBGFEN(1,"ExeFK",NULL);
  177.  
  178.     if (CmdMod & MARGIS) {            /* if it's m,nFK */
  179.         ErrStr(ERR_ILL, "m,nFK");    /* illegal command "m,nFK" */
  180.         DBGFEX(1,DbgFNm,"FAILURE");
  181.         return FAILURE;
  182.     }
  183.  
  184.     if (CmdMod & DCOLON) {            /* if it's ::FK */
  185.         ErrStr(ERR_ILL, "::FK");    /* illegal command "::FK" */
  186.         DBGFEX(1,DbgFNm,"FAILURE");
  187.         return FAILURE;
  188.     }
  189.  
  190.     SrcTyp = FK_SEARCH;
  191.  
  192.     if (Search(FALSE) == FAILURE) {
  193.         DBGFEX(1,DbgFNm,"FAILURE");
  194.         return FAILURE;
  195.     }
  196.  
  197.     CmdMod = '\0';                /* clear modifiers flags */
  198.  
  199.     DBGFEX(1,DbgFNm,"SUCCESS");
  200.     return SUCCESS;
  201. }
  202.  
  203. /*****************************************************************************
  204.  
  205.     ExeFLs()
  206.  
  207.     This function executes a F< command.
  208.  
  209. *****************************************************************************/
  210.  
  211. static DEFAULT ExeFLs()            /* execute an F< command */
  212. {
  213.     DBGFEN(1,"ExeFLs",NULL);
  214.  
  215.     CmdMod = '\0';                /* clear modifiers flags */
  216.     EStTop = EStBot;            /* clear expression stack */
  217.     CBfPtr = (LStTop == LStBot) ? CStBeg-1 : LStack[LStTop].LAddr;
  218.  
  219.     DBGFEX(1,DbgFNm,"SUCCESS");
  220.     return SUCCESS;
  221. }
  222.  
  223. /*****************************************************************************
  224.  
  225.     ExeFN()
  226.  
  227.     This function executes a FN command.
  228.  
  229. *****************************************************************************/
  230.  
  231. static DEFAULT ExeFN()            /* execute an FN command */
  232. {
  233.     DBGFEN(1,"ExeFN",NULL);
  234.  
  235. /*
  236.  * The command m,nFN is illegal: the user should use m,nFC
  237.  */
  238.  
  239.     if (CmdMod & MARGIS) {            /* if it's m,nFN */
  240.         ErrStr(ERR_ILL, "m,nFN");    /* illegal command "m,nFN" */
  241.         DBGFEX(1,DbgFNm,"FAILURE");
  242.         return FAILURE;
  243.     }
  244.  
  245.     if (CmdMod & DCOLON) {            /* if it's ::FN */
  246.         ErrStr(ERR_ILL, "::FN");    /* illegal command "::FN" */
  247.         DBGFEX(1,DbgFNm,"FAILURE");
  248.         return FAILURE;
  249.     }
  250.  
  251.     SrcTyp = N_SEARCH;
  252.  
  253.     if (Replac() == FAILURE) {
  254.         DBGFEX(1,DbgFNm,"FAILURE");
  255.         return FAILURE;
  256.     }
  257.  
  258.     CmdMod = '\0';                /* clear modifiers flags */
  259.  
  260.     DBGFEX(1,DbgFNm,"SUCCESS");
  261.     return SUCCESS;
  262. }
  263.  
  264. /*****************************************************************************
  265.  
  266.     ExeFR()
  267.  
  268.     This function executes a FR command.
  269.  
  270. *****************************************************************************/
  271.  
  272. static DEFAULT ExeFR()            /* execute an FR command */
  273. {
  274.     DBGFEN(1,"ExeFR",NULL);
  275.  
  276.     if ((GapBeg-RefLen) < EBfBeg) {        /* if out of range */
  277.         ErrMsg(ERR_DTB);        /* DTB = "delete too big" */
  278.         DBGFEX(1,DbgFNm,"FAILURE");
  279.         return FAILURE;
  280.     }
  281.  
  282.     GapBeg += RefLen;            /* delete */
  283.  
  284.     CmdMod = (CmdMod & COLON);        /* retain only colon bit */
  285.     EStTop = EStBot;            /* clear expression stack */
  286.  
  287.     DBGFEX(1,DbgFNm,"ExeI()");
  288.     return ExeI();
  289. }
  290.  
  291. /*****************************************************************************
  292.  
  293.     ExeFS()
  294.  
  295.     This function executes a FS command.
  296.  
  297. *****************************************************************************/
  298.  
  299. static DEFAULT ExeFS()            /* execute an FS command */
  300. {
  301.     DBGFEN(1,"ExeFS",NULL);
  302.  
  303. /*
  304.  * The command m,nFS is illegal: the user should use m,nFC
  305.  */
  306.  
  307.     if (CmdMod & MARGIS) {            /* if it's m,nFS */
  308.         ErrStr(ERR_ILL, "m,nFS");    /* illegal command "m,nFS" */
  309.         DBGFEX(1,DbgFNm,"FAILURE");
  310.         return FAILURE;
  311.     }
  312.  
  313. /*
  314.  * If it's ::FStext$,  it's a compare,  not a search.  The text argument is
  315.  * compared to the characters immediately following the character pointer.
  316.  * It returns -1 if the strings match, else 0.  A ::FStext$ command is
  317.  * equivalent to a .,.+1:FCtext$ command, so that's the way it's implemented.
  318.  */
  319.  
  320.     if (CmdMod & DCOLON) {            /* if it's ::FS */
  321.         if (CmdMod & MARGIS) {        /* if it's m,n::FS */
  322.             ErrStr(ERR_ILL, "m,n::FS");
  323.             DBGFEX(1,DbgFNm,"FAILURE");
  324.             return FAILURE;
  325.         }
  326.         if (EStTop > EStBot) {        /* if it's n::FS */
  327.             ErrStr(ERR_ILL, "n::FS");
  328.             DBGFEX(1,DbgFNm,"FAILURE");
  329.             return FAILURE;
  330.         }
  331.         if (GapEnd == EBfEnd) {        /* if nothing to search */
  332.             CmdMod = '\0';        /* clear modifiers flags */
  333.             DBGFEX(1,DbgFNm,"PushEx(0)");
  334.             return PushEx(0L,OPERAND);
  335.         }
  336.         CmdMod &= ~DCOLON;        /* clear double-colon bit */
  337.         CmdMod |= COLON;        /* set colon bit */
  338.         CmdMod |= MARGIS;        /* set m defined bit */
  339.         MArgmt = GapBeg - EBfBeg;    /* set m */
  340.         if (PushEx((LONG)((GapBeg-EBfBeg)+1),OPERAND) == FAILURE) {
  341.             DBGFEX(1,DbgFNm,"FAILURE, PushEx() failed");
  342.             return FAILURE;
  343.         }
  344.         DBGFEX(1,DbgFNm,"ExeFC()");
  345.         return ExeFC();            /* execute FC command */
  346.     }
  347.  
  348.     SrcTyp = S_SEARCH;
  349.     if (Replac() == FAILURE) {
  350.         DBGFEX(1,DbgFNm,"FAILURE, Replac() failed");
  351.         return FAILURE;
  352.     }
  353.  
  354.     CmdMod = '\0';                /* clear modifiers flags */
  355.  
  356.     DBGFEX(1,DbgFNm,"SUCCESS");
  357.     return SUCCESS;
  358. }
  359.  
  360. /*****************************************************************************
  361.  
  362.     ExeFSQ()
  363.  
  364.     This function executes a F' command.
  365.  
  366. *****************************************************************************/
  367.  
  368. static DEFAULT ExeFSQ()                /* execute an F' command */
  369. {
  370.     DBGFEN(1,"ExeFSQ",NULL);
  371.  
  372.     CmdMod = '\0';                /* clear modifiers flags */
  373.     EStTop = EStBot;            /* clear expression stack */
  374.  
  375.     DBGFEX(1,DbgFNm,"FlowEC()");
  376.     return FlowEC();
  377. }
  378.  
  379. /*****************************************************************************
  380.  
  381.     ExeFUn()
  382.  
  383.     This function executes a F_ command.
  384.  
  385. *****************************************************************************/
  386.  
  387. static DEFAULT ExeFUn()                /* execute an F_ command */
  388. {
  389.     DBGFEN(1,"ExeFUn",NULL);
  390.  
  391. /*
  392.  * The command m,nF_ is illegal: the user should use m,nFC
  393.  */
  394.  
  395.  
  396.     if (CmdMod & MARGIS) {            /* if it's m,nF_ */
  397.         ErrStr(ERR_ILL, "m,nF_");    /* illegal command "m,nF_" */
  398.         DBGFEX(1,DbgFNm,"FAILURE");
  399.         return FAILURE;
  400.     }
  401.  
  402.     if (CmdMod & DCOLON) {            /* if it's ::F_ */
  403.         ErrStr(ERR_ILL, "::F_");    /* illegal command "::F_" */
  404.         DBGFEX(1,DbgFNm,"FAILURE");
  405.         return FAILURE;
  406.     }
  407.  
  408.     SrcTyp = U_SEARCH;
  409.  
  410.     if (Replac() == FAILURE) {
  411.         DBGFEX(1,DbgFNm,"FAILURE");
  412.         return FAILURE;
  413.     }
  414.  
  415.     CmdMod = '\0';                /* clear modifiers flags */
  416.  
  417.     DBGFEX(1,DbgFNm,"SUCCESS");
  418.     return SUCCESS;
  419. }
  420.  
  421. /*****************************************************************************
  422.  
  423.     ExeF()
  424.  
  425.     This function executes an F command.
  426.  
  427. *****************************************************************************/
  428.  
  429. DEFAULT ExeF()                /* execute one of the F commands */
  430. {
  431.     if (IncCBP() == FAILURE) {
  432.         return FAILURE;
  433.     }
  434.  
  435.     switch (To_Upper(*CBfPtr)) {
  436.           case 'S':  return ExeFS();
  437.       case 'N':  return ExeFN();
  438.       case 'D':  return ExeFD();
  439.       case 'R':  return ExeFR();
  440.       case 'B':  return ExeFB();
  441.       case 'C':  return ExeFC();
  442.       case 'K':  return ExeFK();
  443.       case '_':  return ExeFUn();
  444.       case '>':  return ExeFGt();
  445.       case '<':  return ExeFLs();
  446.       case '\'': return ExeFSQ();
  447.       case '|':  return ExeFBr();
  448.       default:   ErrChr(ERR_IFC, *CBfPtr);
  449.              return FAILURE;
  450.     }
  451. }
  452.